<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop">
            <div style="width: 100%">
                <div style="float: left; width: 70%">
                    <table style="font-size: 17px" class="table1style">
                        <tr>
                            <td style="font-weight: bold">
                                {{ barcodearriveloginmode == "0" ? "条码号(或工号)：" : "条码号：" }}
                            </td>
                            <td>
                                <el-input v-model="txtbarcode" :placeholder="showtext" style="width: 450px" @keyup.enter.native="scanBarcode(txtbarcode)" ref="barcode" id="barcodediv" @click.native="HightlightPos(txtbarcode)" size="medium" @dblclick.native="verifyUser" :readonly="readonly"></el-input>
                            </td>
                            <td align="right">运送人：</td>
                            <td align="right">
                                <!-- <el-input v-model="userinfoname" readonly size="medium" style="width:100px"></el-input> -->
                                {{ userinfoname }}
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="float: left; width: 30%">
                    <table style="float: right" class="top-deal">
                        <tr>
                            <td>
                                <el-button v-show="isclickconfirmbtn == '1'" @click.native="btnArrive()" icon="el-icon-printer">送  达</el-button>
                            </td>
                            <td>
                                <el-button @click.native="btnPrint($event)" icon="el-icon-printer">打 印</el-button>
                            </td>
                            <td>
                                <el-button @click.native="btnClear" icon="el-icon-close">清 除</el-button>
                            </td>
                            <td>
                                <el-button icon="el-icon-setting" @click.native="dialogSetting = true">设置</el-button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="pagecenter">
            <div class="middle-left">
                <vxe-table show-overflow ref="xTable1" height="auto" :select-config="{ reserve: true }" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :data.sync="list" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @current-change="detailretrieve" :loading="loading">
                    <vxe-table-column field="req_groupna" title="分单类别" width="95" header-align="center">
                        <template v-slot="{ row }">{{ !row.req_groupna ? "未分类" : row.req_groupna }}</template>
                    </vxe-table-column>
                    <vxe-table-column field="specimen_name" title="标本类型" width="75" header-align="center"></vxe-table-column>
                    <vxe-table-column field="samplecnt" title="数量" width="55" header-align="center"> </vxe-table-column>
                    <!-- <template v-slot:fix>
                        <div style="font-size: 17px; text-align: center; background-color: #fff; overflow: auto; cursor: pointer" @click="ShowAllData">
                            <span style="font-weight: bold; color: blue">合计：{{ sampleSum }}</span>
                        </div>
                    </template> -->
                </vxe-table>
                <div class="fixbottom">
                    <div style="font-size: 17px; text-align: center; background-color: #fff; overflow: auto; cursor: pointer" @click="ShowAllData">
                            <span style="font-weight: bold; color: blue">合计：{{ sampleSum }}</span>
                        </div>
                </div>
            </div>
            <div class="middle-center">
                <vxe-table show-overflow ref="xTable2" height="auto" row-id="id" :select-config="{ reserve: true }" :data.sync="rowclick ? tempData2 : tableData2" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe>
                    <vxe-table-column type="index" title="NO." width="40" align="center"></vxe-table-column>
                    <vxe-table-column field="req_groupna" title="分单类别" width="96" header-align="center">
                        <template v-slot="{ row }">
                            <div v-bind:style="{ background: $pub.ColorChange(row.tube_color), color: $pub.colorConvert(row.tube_color) }">{{ row.req_groupna }}</div>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="req_deptname" title="申请科室" width="104" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_wardname" title="病人病区 " width="105" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_bedno" title="床号 " width="64" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_name" title="姓名 " width="74" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_sexname" title="性别 " width="48" header-align="center" align="center"></vxe-table-column>
                    <vxe-table-column field="req_statname" title="申请状态 " width="92" header-align="center"></vxe-table-column>
                    <vxe-table-column field="barcode" title="条码号 " width="107" header-align="center"></vxe-table-column>
                    <vxe-table-column field="emer_flag" title="加急 " width="58" header-align="center" align="center">
                        <template v-slot="{ row }">
                            <div style="color: red">{{ row.emer_flag == "0" ? "" : "急" }}</div>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="sample_items" title="项目描述 " width="203" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reject_reason" title="退回原因 " width="205" header-align="center"></vxe-table-column>
                    <vxe-table-column field="base_amount" title="基准总金额 " width="85" header-align="center" align="right"></vxe-table-column>
                    <vxe-table-column field="pat_no" title="病人号 " width="105" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_docname" title="申请医生 " width="75" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_typename" title="病人类型 " width="77" header-align="center" align="center"></vxe-table-column>
                    <vxe-table-column field="create_dt" title="条码生成时间 " width="130" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="create_username" title="条码生成用户" width="100" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reject_username" title="退回用户" width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reject_dt" title="退回时间 " width="98" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="print_dt" title="打印日期 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="print_username" title="打印用户 " width="78" header-align="center"></vxe-table-column>
                    <vxe-table-column field="print_count" title="打印次数 " width="78" header-align="center" align="right"></vxe-table-column>
                    <vxe-table-column field="sampled_dt" title="采样时间 " width="121" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="sampled_username" title="采样用户 " width="83" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_dt" title="申请日期 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="pat_diag" title="临床诊断 " width="133" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_agestr" title="年龄字串 " width="78" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_id" title="病人唯一号 " width="107" header-align="center"></vxe-table-column>
                    <vxe-table-column field="inp_date" title="入院日期 " width="93" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="send_dt" title="护工交接时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="send_username" title="送出护工 " width="83" header-align="center"></vxe-table-column>
                    <vxe-table-column field="recieve_dt" title="检验科接收时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="recieve_username" title="检验科接收用户 " width="123" header-align="center"></vxe-table-column>
                    <vxe-table-column field="charge_dt" title="计价时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="charge_username" title="计价人 " width="74" header-align="center"></vxe-table-column>
                    <vxe-table-column field="amount" title="实收总金额 " width="100" header-align="center" align="right"></vxe-table-column>
                    <vxe-table-column field="charge_flag" title="收费" width="73" header-align="center" :edit-render="{ name: 'select', options: $opt.chargeOption }"></vxe-table-column>
                    <vxe-table-column field="test_dt" title="上机时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="test_username" title="上机用户 " width="106" header-align="center"></vxe-table-column>
                    <vxe-table-column field="report_dt" title="报告时间 " width="134" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="report_username" title="检验医生姓名 " width="92" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rechk_username" title="核对医生姓名 " width="92" header-align="center"></vxe-table-column>
                    <vxe-table-column field="alter_flag" title="警告标志 " width="82" header-align="center"></vxe-table-column>
                    <vxe-table-column field="saleman" title="所属销售人 " width="93" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_cardno" title="就诊卡号 " width="129" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_comm" title="医生备注 " width="197" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_birth" title="病人生日 " width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="pat_ageyear" title="年龄岁数 " width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="inp_id" title="住院标识 " width="76" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_diag_icd" title="诊断的ICD10编码 " width="121" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_address" title="病人联系地址 " width="145" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_nation" title="国家/民族 " width="94" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_idcardno" title="身份证号护照号 " width="142" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_phone" title="联系电话 " width="84" header-align="center"></vxe-table-column>
                    <vxe-table-column field="charge_typename" title="收费类型 " width="82" header-align="center"></vxe-table-column>
                    <vxe-table-column field="perform_deptname" title="执行科室 " width="83" header-align="center"></vxe-table-column>
                    <vxe-table-column field="original_reqno" title="原始单号 " width="90" header-align="center"></vxe-table-column>
                    <vxe-table-column field="secrecy" title="加密标志 " width="77" header-align="center"></vxe-table-column>
                    <vxe-table-column field="other_stat" title="备用标志 " width="76" header-align="center"></vxe-table-column>
                    <vxe-table-column field="cancel_dt" title="作废时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="cancel_username" title="作废用户 " width="75" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reject_count" title="退回次数 " width="70" header-align="center"></vxe-table-column>
                    <vxe-table-column field="specimen_code" title="标本类型 " width="74" header-align="center"></vxe-table-column>
                    <vxe-table-column field="sample_detail" title="标本备注说明 " width="101" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_reason" title="送检目的 " width="107" header-align="center"></vxe-table-column>
                    <vxe-table-column field="multi_seq" title="多条码序号 " width="100" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_groupid" title="分单类别 " width="100" header-align="center"></vxe-table-column>
                    <vxe-table-column field="report_id" title="报告单ID " width="81" header-align="center"></vxe-table-column>
                    <vxe-table-column field="report_user" title="检验医生 " width="81" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rechk_user" title="核对医生 " width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="recieve1_dt" title="工作组接收时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="recieve1_username" title="工作组接收用户 " width="109" header-align="center"></vxe-table-column>
                    <vxe-table-column field="inlib_status" title="入库状态 " width="82" header-align="center"></vxe-table-column>
                    <vxe-table-column field="library_id" title="所在库位ID " width="82" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reqtype" title="申请业务类别 " width="88" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_height" title="身高 " width="65" header-align="center"></vxe-table-column>
                    <vxe-table-column field="weight" title="体重 " width="71" header-align="center"></vxe-table-column>
                    <vxe-table-column field="abo_bldtype" title="ABO血型 " width="90" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rh_bldtype" title="RH血型 " width="94" header-align="center"></vxe-table-column>
                    <vxe-table-column field="hospcodename" title="送检医院 " width="133" header-align="center"></vxe-table-column>
                    <vxe-table-column field="recieve_host" title="检验科接收电脑 " width="125" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rcvmsg" title="签收消息 " width="165" header-align="center"></vxe-table-column>

                    <vxe-table-column field="req_deptno" title="申请科室 " width="84" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_wardno" title="病人病区 " width="85" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_sex" title="性别 " width="50" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_stat" title="申请状态 " width="52" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_docno" title="申请医生 " width="75" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_typecode" title="病人类型 " width="77" header-align="center"></vxe-table-column>
                    <vxe-table-column field="create_user" title="条码生成人 " width="84" header-align="center"></vxe-table-column>
                    <vxe-table-column field="reject_user" title="退回用户 " width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="print_user" title="打印用户 " width="81" header-align="center"></vxe-table-column>
                    <vxe-table-column field="sampled_user" title="采样用户 " width="83" header-align="center"></vxe-table-column>
                    <vxe-table-column field="send_user" title="送出护工 " width="83" header-align="center"></vxe-table-column>
                    <vxe-table-column field="recieve_user" title="检验科接收用户 " width="123" header-align="center"></vxe-table-column>
                    <vxe-table-column field="charge_user" title="计价人 " width="74" header-align="center"></vxe-table-column>
                    <vxe-table-column field="test_user" title="上机用户 " width="76" header-align="center"></vxe-table-column>
                    <vxe-table-column field="charge_typeno" title="收费类型 " width="72" header-align="center"></vxe-table-column>
                    <vxe-table-column field="perform_dept" title="执行科室 " width="73" header-align="center"></vxe-table-column>
                    <vxe-table-column field="cancel_user" title="作废用户 " width="75" header-align="center"></vxe-table-column>
                    <vxe-table-column field="report_user" title="检验医生 " width="71" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rechk_user" title="核对医生 " width="70" header-align="center"></vxe-table-column>
                    <vxe-table-column field="recieve1_user" title="工作组接收用户 " width="109" header-align="center"></vxe-table-column>
                    <vxe-table-column field="hospcode" title="送检医院 " width="123" header-align="center"></vxe-table-column>
                </vxe-table>
            </div>
        </div>
        <!--签收打包条码-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="签收打包条码" :visible.sync="dialogPackageRcv" width="1000px" :show-close="false">
            <rm-PackageBar-Rcv @cancel="packageCancel" :tableData1="packagedata" :remindtxt="remindstr" @appendDialog="appendDialog" :userinfoval="userinfoval" :trans="trans" name="LIS211"></rm-PackageBar-Rcv>
        </el-dialog>
        <!--标本签收-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="标本签收" :visible.sync="dialogSpecimenRcv" width="1000px" :show-close="false">
            <rm-Specimen-Rcv :tableData2="specimenData" @cancel="specimenCancel" :userinfoval="userinfoval" :packagebarcode="packagebarcode" name="LIS211" :key="specimenkey"></rm-Specimen-Rcv>
        </el-dialog>
        <!--选项设置弹窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="LIS211标本送达" :visible.sync="dialogSetting" width="500px">
            <div style="height: 450px">
                <rm_GeneralOptions_page URL="MNG/MNG1/MNG137" SQLKEY="PRG" OptionClass="本地" :isdialog="true" checkOne="LIS211"></rm_GeneralOptions_page>
            </div>
        </el-dialog>
        <!--送达提示-->
        <el-dialog title="送达提示" :visible.sync="dialog_arrivetips" v-el-drag-dialog :close-on-click-modal="false" width="500px">
            <div style="height: 100px;">
                <h2 style="color: red">{{ arrivetips }}</h2>
            </div>
            <div slot="footer">
                <el-button icon="el-icon-circle-check" @click="arrivedialogcancel" :autofocus="true">确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import { Select } from "element-ui";
import XEUtils from "xe-utils";
export default {
    name: "LIS211",
    data() {
        return {
            dialogSetting: false,
            loading: false,
            tableData1: [],
            tableData2: [],
            tempData2: [],
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            txtbarcode: "",
            barcodearrivemode: "",
            // 0=仅更新包条码交接时间，只能扫描包条码，扫描后弹窗有确认和取消按钮，确认的时候再更新状态
            //1=仅记录申请单送达日志
            // 2=更新申请单送达时间和送达人
            judgercvrule: "", //即使不签收也要判断签收条件
            packagemustscan1by1: "", //打包条码必须解包逐个扫描
            barcodearriveloginmode: "", //登陆模式
            showerrormsgbox: "", //错误信息是否弹出提示框
            userinfoval: "",
            userinfoname: "",
            dialogPackageRcv: false,
            dialogSpecimenRcv: false,
            packagedata: [],
            specimenData: [],
            remindstr: "",
            trans: "",
            packagebarcode: "",
            rowclick: false,
            userno: this.$tool.getSession(this.$tool.loginuserno),
            showtext: this.barcodearriveloginmode == "0" ? "请扫描条码号或工号" : "请扫描条码号",
            readonly: true,
            ReqSendstyleid: "",
            specimenkey: 0,
            isclickconfirmbtn: "",
            dialog_arrivetips: false,
            arrivetips: "",
            rcvusetts : "",
            rcvtts_normal : "",
            rcvtts_emer: "",
            scanjobnumtoarrive: "",
            jobNum: "",
        };
    },
    created() {
        this.InitPage(); //初始化主列表
    },
    mounted() {
        this.$refs.barcode.focus();
    },
    updated() {},
    computed: {
        list() {
            if (this.tableData2.length > 0) {
                this.tableData1 = this.group(this.tableData2, function (item) {
                    return item.req_groupna + "," + item.specimen_name;
                });
                return this.tableData1;
            }
        },
        sampleSum() {
            if (this.tableData1.length > 0) {
                return XEUtils.sum(this.tableData1, "samplecnt");
            }
        },
    },
    methods: {
        InitPage() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS211",
                    method: "post",
                    data: {
                        action: "getoptions",
                    },
                })
                .then((res) => {
                    this.barcodearrivemode = res.barcodearrivemode;
                    this.judgercvrule = res.judgercvrule; //即使不签收也要判断签收条件
                    this.packagemustscan1by1 = res.packagemustscan1by1; //打包条码必须解包逐个扫描
                    this.barcodearriveloginmode = res.barcodearriveloginmode == "" ? "0" : res.barcodearriveloginmode; //登录模式
                    this.showerrormsgbox = res.showerrormsgbox; //错误信息是否弹出提示框
                    this.ReqSendstyleid = res.ReqSendstyle; //送达清单样式ID
                    this.rcvusetts = res.rcvusetts; //签收启用语音提醒
                    this.rcvtts_normal = res.rcvtts_normal; //正常签收播报文字
                    this.rcvtts_emer = res.rcvtts_emer; //急诊标本签收播报文字
                    this.scanjobnumtoarrive = res.scanjobnumtoarrive; //扫描工号进行送达

                    if(this.barcodearrivemode != "0"){
                        this.isclickconfirmbtn = res.isclickconfirmbtn; //是否点击送达确认按钮进行送达
                    }
                    this.verifyUser();
                })
                .catch((e) => {
                    console.log("error", e);
                });
        },

        group(list, f) {
            //分组函数
            const groups = {};
            list.forEach(function (re) {
                const group = f(re);
                groups[group] = groups[group] || [];
                groups[group].push(re);
            });
            return Object.keys(groups).map(function (group) {
                let groupLabel = group.split(","); //根据“，”切割成数组（可自定义）
                return {
                    req_groupna: groupLabel[0], //分单类别
                    specimen_name: groupLabel[1], //标本类型
                    samplecnt: groups[group].length, //
                };
            });
        },
        async verifyUser(userno) {
            if (this.barcodearriveloginmode == "0") {
                //扫描工牌登录模式
                this.readonly = false;
                if (!userno) return false;
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS211",
                    method: "post",
                    data: {
                        action: "verifyUser",
                        userno: userno,
                    },
                });
                return res;
            } else if (this.barcodearriveloginmode == "1") {
                //护工需要先登录程序
                this.$rm_Login({
                    type: "用户登录验证",
                    btn: {
                        confirmBtnText: "确定",
                        cancelBtnText: "取消",
                    },
                })
                    .then((res) => {
                        if (res.flag == "1") {
                            //登录成功
                            this.jobNum = res.userid;//工号
                            this.userinfoval = res.userid;
                            this.userinfoname = res.username;
                            this.txtbarcode = "请扫描条码";
                            this.readonly = false;
                        } else {
                            //登录失败
                            this.jobNum = "";
                            this.userinfoval = "";
                            this.userinfoname = "";
                            this.readonly = true;
                        }
                    })
                    .catch((e) => {
                        this.txtbarcode = "请先双击登录程序后再操作";
                        this.readonly = true;
                    });
            } else {
                //保存时再登录程序，默认值为2,说暂时不做，但是因为数据问题，暂时与0同
                this.readonly = false;
                if (!userno) return false;
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS211",
                    method: "post",
                    data: {
                        action: "verifyUser",
                        userno: userno,
                    },
                });
                return res;
            }
        },
        async scanBarcode(txtbarcode) {
            var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
            if (reg.test(txtbarcode)) {
                //避免弹窗后按钮回车再次走入这个事件
                return false;
            }
            this.ShowAllData();//清除左边分类的选中，显示所有数据
            if (!this.userinfoval) {
                let verifydata = await this.verifyUser(txtbarcode);
                if (verifydata.flag == "1") {
                    this.jobNum = txtbarcode;//工号
                    this.userinfoval = verifydata.userid;
                    this.userinfoname = verifydata.username;
                } else {
                    this.txtbarcode = "请扫描工号登录！";
                    if(this.rcvusetts == '1') {
                        this.speakMessage("请扫描工号登录！");
                    }
                }
                if (this.barcodearriveloginmode == "0" && !this.userinfoval)
                {
                    this.dialog_arrivetips = true;
                    this.arrivetips = "请先扫描工号登录！";
                    if(this.rcvusetts == '1') {
                        this.speakMessage("请先扫描工号登录！");
                    }
                }
                this.HightlightPos(this.txtbarcode);
                return false;
            }
            else {
                //已登录的情况
                if(this.scanjobnumtoarrive == '1' && !!this.jobNum && this.jobNum == txtbarcode){
                    //送达
                    setTimeout(() => {
                        this.btnArrive();
                    }, 10);
                    return false;
                }
            }
            // 列表是否已存在
            let data = this.$refs.xTable2.getTableData().fullData.filter(m=>m.barcode == txtbarcode);
            if(data.length > 0){
                this.txtbarcode = txtbarcode + "  已扫描！";
                if(this.showerrormsgbox == '1'){
                    //错误消息弹出框
                    this.dialog_arrivetips = true;
                    this.arrivetips = this.txtbarcode;
                }
                if(this.rcvusetts == '1') {
                    this.speakMessage("条码已扫描！");
                }
                return false;
            }else{
                try {
                    const res = await this.$tool.request({
                        url: "LIS/LIS2/LIS211",
                        method: "post",
                        data: {
                            action: "scanbarcode",
                            barcode: txtbarcode,
                            senduser1: this.userinfoval,
                        },
                    });
                    //消息显示处理
                    switch (res.flag) {
                        case 1:
                            this.txtbarcode = res.msg;
                            if (this.barcodearrivemode != "0") {
                                this.tableData2.splice(0, 0, res.master);
                                this.$refs.xTable2.setCurrentRow(res.master);
                                if(this.isclickconfirmbtn != '1'){
                                    //直接送达，则进行语音提示
                                    if(this.rcvusetts == '1') {
                                        if(res.master.emer_flag == '1'){
                                            //急诊标本
                                            this.speakMessage(this.rcvtts_emer);
                                        }
                                        else{
                                            //普通标本
                                            this.speakMessage(this.rcvtts_normal);
                                        }
                                    }
                                }
                            } else {
                                this.txtbarcode = txtbarcode + "  更新包条码交接时间完成！";
                                this.$refs.barcode.select();
                                if(this.rcvusetts == '1') {
                                    if(res.master.emer_flag == '1'){
                                        //急诊标本
                                        this.speakMessage(this.rcvtts_emer);
                                    }
                                    else{
                                        //普通标本
                                        this.speakMessage(this.rcvtts_normal);
                                    }
                                }
                            }

                            break;
                        case -99:
                            this.txtbarcode = res.errmsg;
                            if(this.showerrormsgbox == '1'){
                                //错误消息弹出框
                                this.dialog_arrivetips = true;
                                this.arrivetips = this.txtbarcode;
                            }
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.errmsg);
                            }
                            break;
                        case 97: //97标识包条码返回
                            //this.txtbarcode = this.txtbarcode + " 出错!" + res.msg;
                            this.dialog_arrivetips = true;
                            this.arrivetips = res.msg;
                            this.txtbarcode = "";
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.msg);
                            }
                            break;
                        case 98: //98/99标识包条码返回
                            this.txtbarcode = this.txtbarcode + " 出错!" + res.msg;
                            if(this.showerrormsgbox == '1'){
                                //错误消息弹出框
                                this.dialog_arrivetips = true;
                                this.arrivetips = this.txtbarcode;
                            }
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.msg);
                            }
                            break;
                        case 99: //99表示包条码获取成功
                            let data = res.pkgdetail;
                            let alen = res.pkgdetail.length;
                            // console.log("data", res.pkgdetail);
                            this.packagedata = await [];
                            this.dialogPackageRcv = true;
                            if (data && data.length > 0) {
                                //如果存在值为req_stat=null的数据，则循环传入barcode
                                let barnum = 0;
                                for (const item of data) {
                                    if (item.req_stat == null) {
                                        let gitem = await this.getbarcodeinfo(item.barcode);
                                        if (!gitem) {
                                            //没有错误，但是申请单没找到
                                            await this.packagedata.push(item);
                                        } else {
                                            //找到申请单
                                            if (gitem != "-1") {
                                                await this.packagedata.push(gitem);
                                            }
                                        }
                                    } else {
                                        await this.packagedata.push(item);
                                    }
                                    barnum++;
                                    this.remindstr = "正在获取第" + barnum + "个条码信息，条码号" + item.barcode + " (" + barnum + "/" + alen + ")";
                                }
                                this.trans = res.trans.packagebarcode + "|" + res.trans.transtype;
                                this.remindstr = "所有条码信息获取完成" + " (" + alen + "/" + alen + ")";
                            } else {
                                this.packagedata = [];
                                this.remindstr = "没有获取到条码信息" + " ( 0 / 0)";
                            }

                            break;
                        case 100: //100标识包条码包含明细条码重复扫描返回
                            this.dialog_arrivetips = true;
                            this.arrivetips = res.msg;
                            this.txtbarcode = "";
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.msg);
                            }
                            break;
                        default:
                            this.txtbarcode = this.txtbarcode + " " + res.msg;
                            if(this.showerrormsgbox == '1'){
                                //错误消息弹出框
                                this.dialog_arrivetips = true;
                                this.arrivetips = this.txtbarcode;
                            }
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.msg);
                            }
                    }
                    this.HightlightPos(this.txtbarcode);
                } catch (e) {
                    console.log("error", e);
                }
            }
        },
        arrivedialogcancel(){
            this.dialog_arrivetips = false;
            this.arrivetips = '';
            //聚焦在扫描条码框
            this.$nextTick(() => {
                this.$refs.barcode.focus();
                this.$refs.barcode.select();
            });
        },
        //消息声音提示
        speakMessage(message) {
            //语音播报
            console.log(" speekstr :", message);
            if (typeof jsObj != "undefined") {
                jsObj.Speek(message);
            } else {
                var u = new SpeechSynthesisUtterance();
                u.text = message;
                u.lang = "zh";
                u.rate = 0.7;
                speechSynthesis.speak(u);
            }
        },
        async getbarcodeinfo(barcode) {
            const res = await this.$tool.request({
                url: "LIS/LIS2/LIS212",
                method: "post",
                data: {
                    action: "getbarcodeinfo",
                    barcode: barcode,
                },
            });
            switch (res.Item1) {
                case 0: //没有错误，但没有找到申请单
                    await this.$alert("条码号为[" + barcode + "]的申请单并没有找到！" + res.Item2);
                    return res.Item3; //值为空
                    break;
                case 1: //找到申请单
                    return res.Item3;
                    break;
                case -1: //失败
                    await this.$alert("获取失败，请检查接口！" + res.Item2);
                    return "-1";
                    break;
            }
        },
        HightlightPos(myValue) {
            if (myValue == "") {
                return false;
            }
            var myField = document.getElementById("barcodediv");
            if (myField.selectionStart || myField.selectionStart === 0) {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                this.$nextTick(() => {
                    myField.selectionStart = 0;
                    myField.selectionEnd = startPos + myValue.length;
                }); // 这句是重点, 圈起来
                myField.focus();
                myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
            }
        },
        detailretrieve({ row }) {
            this.rowclick = true;
            if (this.tableData2.length > 0) {
                //如果点击了统计信息，就显示统计信息下的明细，恢复暂时没要求
                let data = this.tableData2.filter((item) => {
                    return item.specimen_name == row.specimen_name && item.req_groupna == row.req_groupna;
                });
                this.tempData2 = data;
            }
        },
        ShowAllData() {
            this.rowclick = false; //扫描一个新的条码回到未过滤的状态
            this.$refs.xTable1.clearCurrentRow();
        },
        btnClear() {
            this.txtbarcode = "";
            this.tableData1 = [];
            this.tableData2 = [];
            this.tempData2 = [];
            this.userinfoval = "";
            this.userinfoname = "";
            this.jobNum = "";
            this.$refs.barcode.focus();
        },
        appendDialog(data, packagebarcode) {
            this.specimenData = data;
            this.packagebarcode = packagebarcode;
            this.specimenkey++;
            this.dialogSpecimenRcv = true;
        },
        async packageCancel(object) {
            this.packagedata = await [];
            this.packmaster = await [];
            this.dialogPackageRcv = false;
            if (object.length > 0) {
                for (const master of object) {
                    let data = this.tableData2.filter((item) => item.barcode == master.barcode);
                    if (data.length == 0) {
                        //await this.reqgroupnaInfo(master); //统计分单类别信息
                        this.tableData2.push(master);
                    }
                }
            }
            this.HightlightPos(this.txtbarcode);
        },
        async specimenCancel(object) {
            this.specimenData = await [];
            this.dialogSpecimenRcv = false;
            this.dialogPackageRcv = false;
            if (object.length > 0) {
                for (const master of object) {
                    //  console.log("calmaster", master);
                    let data = this.tableData2.filter((item) => item.barcode == master.barcode);
                    if (data.length == 0) {
                        // await this.reqgroupnaInfo(master); //统计分单类别信息
                        this.tableData2.push(master);
                    }
                }
            }
            this.HightlightPos(this.txtbarcode);
        },
        btnArrive(){
            // 点击送达
            if(this.tableData2.length > 0){
                this.$tool
                    .request({
                        url: "LIS/LIS2/LIS211",
                        method: "post",
                        data: {
                            action: "arrive",
                            arrivelist: this.tableData2,
                            senduser: this.userinfoval,
                        },
                    })
                    .then((res) => {
                        if(res.flag == "1"){
                            //送达成功
                            if(this.rcvusetts == '1') {
                                this.speakMessage("送达成功！");
                            }
                            this.$confirm("送达成功！是否清除本次数据？", "提示", {
                                confirmButtonText: "确定",
                                cancelButtonText: "取消",
                                showClose: false,
                                type: "success",
                            })
                            .then(() => {
                                //清除
                                this.btnClear();
                            });
                        }
                        else {
                            //送达失败
                            if(this.rcvusetts == '1') {
                                this.speakMessage(res.msg);
                            }
                            this.$alert(res.msg);
                            return false;
                        }
                    })
                    .catch((e) => {
                        console.log("error", e);
                    });
            }
            else {
                this.$alert("送达失败，当前无数据！");
                return false;
            }
        },
        //清单打印
        btnPrint(e) {
            if (!this.ReqSendstyleid) {
                this.$alert("请在申请、采血本地选项页面条码编码规则中选择送达清单格式！");
                return false;
            }
            let dbtype = this.$ddldata.DbType;
            if (e.shiftKey) {
                //调整
                let sql = "select top 1 1 as 条数,'1' as 序号,* from req_master_all_name";
                if(dbtype == "2"){
                    sql = "select  1 as 条数, '1' as 序号,* from req_master_all_name  limit 1";
                }
                else if(dbtype == "3"){
                    sql = "select 1 as 条数,'1' as 序号, req_master_all_name.*  from req_master_all_name where rownum = 1";
                }
                this.$pub.printlistbill(this, sql, "3", this.ReqSendstyleid, "送达清单样式", "");
            } else {
                //打印
                let data = this.tableData2;
                if (data.length > 0) {
                    const rLoading = this.$pub.openLoading(this, "正在打印交接清单……");
                    let barcode = "";
                    let len = data.length;
                    data.forEach((item) => {
                        if (barcode == "") {
                            barcode = item.barcode;
                        } else {
                            barcode = barcode + "','" + item.barcode;
                        }
                    });

                    let  sql = "select '" + len + "' as 条数,row_number() over (order by 条码号) as 序号,* from req_master_all_name where 条码号 in ('" + barcode + "')";
                    if(dbtype == "2"){
                        sql = "select '" + len + "' as 条数,@rownum:=@rownum+1 as 序号, req_master_all_name.* from (select @rownum:=0) r, req_master_all_name  where req_master_all_name.条码号 in ('" + barcode + "')";
                    }
                    else if(dbtype == "3"){
                        sql = "select '" + len + "' as 条数,rownum as 序号,req_master_all_name.* from req_master_all_name where req_master_all_name.条码号 in ('" + barcode + "')";
                    }
                    console.info("sql===="+sql);
                    this.$pub.printlistbill(this, sql, "1", this.ReqSendstyleid, "送达清单样式", "");
                    rLoading.close();
                }
                else{
                    this.$alert("打印失败，未能获取到数据！");
                }

            }
        }
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 55px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 60px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 255px;
    right: 0px;
    overflow: auto;
}

.middle-left {
    position: absolute;
    height: 100%;
    width: 250px;
    left: 0px;
}

.table1style tr td {
    padding: 0px 5px 0px 6px;
}
.top-deal {
    right: 5px;
    position: absolute;
    top: 20px;
    display: flex;
    align-items: center;
}
.fixbottom{
    position: absolute;
    left: 0px;
    bottom: 0%;
    z-index: 1;
    overflow: hidden;
    width: 100%; 
}
</style>